/*
 * Tuple.cpp
 *
 *  Created on: 06/02/2014
 *      Author: Bruno
 */

#include "Tuple.h"
#include <stdio.h>
#include <iostream>

using namespace std;

Tuple::Tuple(int length) {

	this->array = new int[2 * length + 3];
	this->array[0] = -1;
	this->array[1] = 0;
	this->array[2] = 0;
	this->length = length;
}

Tuple::Tuple(int length, int* array) {

	this->length = length;
	this->array = new int[2 * this->length + 3];
	this->array[0] = array[0];
	this->array[1] = array[1];
	this->array[2] = array[2];
	for (int i = 0; i < this->length; i++) {
		this->array[3 + i] = array[3 + i];
		this->array[3 + this->length + i] = array[3 + this->length + i];
	}

}

Tuple::~Tuple() {

	delete[] this->array;
}

Tuple* Tuple::copy() {

	Tuple* t = new Tuple(this->length);
	t->array[0] = this->array[0];
	t->array[1] = this->array[1];
	t->array[2] = this->array[2];
	for (int i = 0; i < this->length; i++) {
		t->array[3 + i] = this->array[3 + i];
		t->array[3 + this->length + i] = this->array[3 + this->length + i];
	}
	return t;
}

int* Tuple::getArray() {
//	int* array = new int[this->length];
//	for(int i = 0; i < this->lenght; i++){
//		array[i] = this->array[i];
//	}
	return array;
}

int Tuple::lastAct() {
	return this->array[0];
}

int Tuple::time() {
	return this->array[1];
}

int Tuple::cost() {
	return this->array[2];
}

int Tuple::times(int act) {
	return this->array[3 + act];
}

int Tuple::modes(int act) {
	return this->array[3 + this->length + act];
}

void Tuple::lastAct(int a) {
	this->array[0] = a;
}

void Tuple::time(int t) {
	this->array[1] = t;
}

void Tuple::cost(int c) {
	this->array[2] = c;
}

void Tuple::times(int act, int t) {
	this->array[3 + act] = t;
}

void Tuple::modes(int act, int m) {
	this->array[3 + this->length + act] = m;
}

int Tuple::getLength() {
	return this->length;
}

void Tuple::sigAct() {
	if (!this->isSolution()) {
		this->array[0]++;
	} else {
		printf("ERROR!!!! sigAct en una solucion\n");
	}
}

bool Tuple::isSolution() {

	bool ret = ((this->length -1) == this->array[0]);
	if(ret){
		//cout<<"es solucion!!!\n";
	}
	return ret;
}

